#include <Arduino.h>
#include <Wire.h>

#define sda 38
#define scl 39

void i2c_scan()
{
  Wire.begin(sda, scl, 100000);
  log_i("\nI2C Scanner");
  log_i("Scanning...");

  byte error, address;
  int nDevices;

  nDevices = 0;
  for (address = 1; address < 127; address++)
  {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      log_i("I2C device found at address 0x%x",address);
      nDevices++;
    }
    else if (error == 4)
    {
      log_e("Unknown error at address 0x");
      if (address < 16)
      {
        log_i("0");
      }
      log_e("0x%02x", address);
    }
  }
  if (nDevices == 0)
  {
    log_e("No I2C devices found\n");
  }
  else
  {
    log_i("done\n");
  }
}